home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 870 b | 50 lines | [TEXT/CWIE] |
- // TemporaryPort.cp
-
- #ifndef TemporaryPort_h
- #include "TemporaryPort.h"
- #endif
- #ifndef GrafPortObject_h
- #include "GrafPortObject.h"
- #endif
- #ifndef QuickDrawError_h
- #include "QuickDrawError.h"
- #endif
-
- bool TemporaryPort::sharedPortBusy = false;
-
- TemporaryPort::TemporaryPort()
- : old( GrafPortObject::Current() )
- {
- if ( sharedPortBusy )
- {
- OpenCPort( &personal );
-
- toUse = reinterpret_cast<GrafPortObject *>( &personal );
- QuickDrawError::Check().Throw();
- }
- else
- {
- static GrafPortObject sharedPort;
- toUse = &sharedPort;
- sharedPortBusy = true;
- }
-
- toUse->BeCurrent();
- }
-
- TemporaryPort::~TemporaryPort()
- {
- old.BeCurrent();
-
- if ( toUse == reinterpret_cast<GrafPortObject *>( &personal ) )
- {
- CloseCPort( &personal );
- QuickDrawError::Check().Throw();
- }
- else
- {
- Assert( sharedPortBusy );
- sharedPortBusy = false;
- }
- }
-